package cn.liontalk.service.impl;

import cn.liontalk.dao.OrderMasterRepository;
import cn.liontalk.dto.OrderDTO;
import cn.liontalk.entity.OrderDetail;
import cn.liontalk.entity.OrderMaster;
import cn.liontalk.enums.OrderStatusEnums;
import cn.liontalk.enums.PayStatusEnums;
import cn.liontalk.service.OrderService;
import cn.liontalk.utils.KeyUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * @author ZhouZhe
 * @version 1.0
 * @description
 * @date 2019-04-16 21:49
 **/
@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    OrderMasterRepository masterRepository;




    @Override
    public OrderDTO create(OrderDTO orderDTO) {

        String orderId = KeyUtil.genUniqueKey();
        //订单入库
        OrderMaster orderMaster = new OrderMaster();
        orderDTO.setOrderId(orderId);
        BeanUtils.copyProperties(orderDTO, orderMaster);
        orderMaster.setOrderAmount(new BigDecimal(4));
        orderMaster.setOrderStatus(OrderStatusEnums.NEW.getCode());
        orderMaster.setPayStatus(PayStatusEnums.WAIT.getCode());
        masterRepository.save(orderMaster);
        return orderDTO;
    }
}
